package com.iflytek.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.iflytek.common.utils.SecurityUtils;
import com.iflytek.exam.domain.ExamSet;
import com.iflytek.exam.service.IExamSetService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iflytek.common.annotation.Log;
import com.iflytek.common.core.controller.BaseController;
import com.iflytek.common.core.domain.AjaxResult;
import com.iflytek.common.enums.BusinessType;
import com.iflytek.exam.domain.ExamGrade;
import com.iflytek.exam.service.IExamGradeService;
import com.iflytek.common.utils.poi.ExcelUtil;
import com.iflytek.common.core.page.TableDataInfo;

/**
 * 试卷成绩Controller
 * 
 * @author KK
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/exam/grade")
public class ExamGradeController extends BaseController
{
    @Autowired
    private IExamGradeService examGradeService;


    /**
     * 查询试卷成绩列表
     */
    @PreAuthorize("@ss.hasPermi('exam:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamGrade examGrade)
    {

        startPage();
        //只能查询当前用户的试卷成绩
        examGrade.setUserId(SecurityUtils.getUserId());
        List<ExamGrade> list = examGradeService.selectExamGradeList(examGrade);
        return getDataTable(list);
    }

    /**
     * 导出试卷成绩列表
     */
    @PreAuthorize("@ss.hasPermi('exam:grade:export')")
    @Log(title = "试卷成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamGrade examGrade)
    {
        List<ExamGrade> list = examGradeService.selectExamGradeList(examGrade);
        ExcelUtil<ExamGrade> util = new ExcelUtil<ExamGrade>(ExamGrade.class);
        util.exportExcel(response, list, "试卷成绩数据");
    }

    /**
     * 获取试卷成绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:grade:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return examGradeService.getInfo(id);
    }

    /**
     * 新增试卷成绩
     */
    @PreAuthorize("@ss.hasPermi('exam:grade:add')")
    @Log(title = "试卷成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamGrade examGrade)
    {
        return toAjax(examGradeService.insertExamGrade(examGrade));
    }

    /**
     * 修改试卷成绩
     */
    @PreAuthorize("@ss.hasPermi('exam:grade:edit')")
    @Log(title = "试卷成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamGrade examGrade)
    {
        return toAjax(examGradeService.updateExamGrade(examGrade));
    }

    /**
     * 删除试卷成绩
     */
    @PreAuthorize("@ss.hasPermi('exam:grade:remove')")
    @Log(title = "试卷成绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examGradeService.deleteExamGradeByIds(ids));
    }
}
